from django.db import models

from utils import choices
import os

def attachment_upload(instance,filename):
    id = "course_" + str(instance.pk)
    (shotname, extension) = os.path.splitext(filename);
    path = os.path.join('images', id, 'course_image'+extension)
    return path

# Create your models here.
class Course(models.Model):
    course_name=models.CharField(
        verbose_name='课程名',
        max_length=50,
        default=''
    )

    status =models.CharField(
        verbose_name='课程状态',
        max_length=20,
        choices=choices.COURSE_STATUS,
        default='1',
    )

    programming_language=models.CharField(
        verbose_name='语言类型',
        max_length=20,
    )

    account_id=models.IntegerField(
        verbose_name='老师ID',
        blank=True
    )

    account_name=models.CharField(
        verbose_name='老师姓名',
        max_length=20
    )

    class_room=models.CharField(
        verbose_name='上课教室',
        max_length=40,
        null=True,
        blank=True
    )

    start_time=models.DateField(
        verbose_name='课程有效时间_起',
        blank=True
    )

    end_time=models.DateField(
        verbose_name='课程有效时间_终',
        blank=True
    )

    assignment_id=models.IntegerField(
        verbose_name='课堂作业ID',
        blank=True
    )
    ti_id=models.IntegerField(
        verbose_name='课堂作业的题ID',
        blank=True,
        default=-1,
    )
    max_num=models.IntegerField(
        verbose_name='课程人数上限',
        blank=True,
        default=0
    )
    number=models.IntegerField(
        verbose_name='人数',
        blank=True,
        default=0,
    )
    apply_number=models.IntegerField(
        verbose_name='申请人数',
        blank=True,
        default=0,
    )
    course_image=models.ImageField(
        verbose_name='课程图片',
        upload_to=attachment_upload,
        blank=True,
        null=True
    )
#    def __str__(self):
#        return  self.course_name


class StudentCourse(models.Model):
    course_id=models.IntegerField(
        verbose_name='课程ID',
        blank=True
    )

    account_id=models.IntegerField(
        verbose_name='学生ID',
        blank=True
    )

    status=models.CharField(
        verbose_name='申请状态',
        choices=choices.COURSE_MEMBER_STATUS,
        default='3',
        max_length=5,
        blank=True,
    )

class Assignment(models.Model):
    course_id=models.IntegerField(
        verbose_name='课程ID',
        blank=True
    )

    create_time=models.DateTimeField(
        verbose_name='作业布置时间',
        blank=True,
        auto_now_add=True,
    )

    dead_line=models.DateField(
        verbose_name='最晚提交时间',
        blank=True,
    )

    title=models.CharField(
        verbose_name='作业标题',
        max_length=80,
        blank=True,
    )

    type=models.CharField(
        verbose_name='作业类型',
        max_length=20,
        choices=choices.HOMEWORK_TYPE_CHOICES,
        default='0',
    )


class MyAssignment(models.Model):
    account_id=models.IntegerField(
        verbose_name='用户ID',
        blank=True,
    )

    assignment_id=models.IntegerField(
        verbose_name='作业ID',
        blank=True,
    )

    ti_id = models.IntegerField(
        verbose_name='题目ID',
        blank=True,
        default=-1,
    )

    project_id=models.IntegerField(
        verbose_name='项目ID',
        blank=True,
        default=-1,
    )

    submited=models.NullBooleanField(
        verbose_name='已提交',
        default=False,
        blank=True,
        null=True,
    )

    compile_successed=models.NullBooleanField(
        verbose_name='已编译成功',
        default=False,
        blank=True,
        null=True,
    )

    updated_time=models.DateTimeField(
        verbose_name='最后更新时间',
        auto_now=True
    )


class MyProjects(models.Model):
    account_id=models.IntegerField(
        verbose_name='用户ID',
    )

    project_id = models.IntegerField(
        verbose_name='项目ID',
        null=True,
        blank=True
    )

    programming_language = models.CharField(
        verbose_name='语言类型',
        max_length=40,
        blank=True
    )

    project_name=models.CharField(
        verbose_name='项目名称',
        max_length=40,
        blank=True
    )

    received=models.BooleanField(
        verbose_name='已接收',
        default=False,
        blank=True
    )


class Ti(models.Model):
    course_id = models.IntegerField(
        verbose_name='课程ID',
        blank=True
    )

    assignment_id=models.IntegerField(
        verbose_name='作业ID',
        blank=True
    )

    text=models.TextField(
        verbose_name='作业内容',
        max_length=1000,
        null=True,
        blank=True
    )
















